package br3akr.DeadlyDinnerParty.Server.Actions;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import br3akr.DeadlyDinnerParty.Server.World.Area;
import br3akr.DeadlyDinnerParty.Server.World.GameCharacter;

public class ActionResponse {
	private GameCharacter actingCharacter;
	private Set<GameCharacter> targetCharacters;
	private Set<GameCharacter> onlookers;
	Set<Area> affectedAreas;
	
	private String actingCharacterDescription;
	private Map<GameCharacter, String> targetDescriptions;
	private Map<GameCharacter, String> onlookerDescriptions;
	
	private String systemMessage;
	
	private boolean actionCompleted = false;
	private boolean actionError = false;
	
	public ActionResponse() {
		affectedAreas = new HashSet<Area>();
		targetCharacters = new HashSet<GameCharacter>();
		onlookers = new HashSet<GameCharacter>();
		targetDescriptions = new HashMap<GameCharacter, String>();
		onlookerDescriptions = new HashMap<GameCharacter, String>();
	}
	
	public void addAffectedArea(Area area) {
		affectedAreas.add(area);
	}
	
	public void removeAffectedArea(Area area) {
		affectedAreas.remove(area);
	}
	
	public Set<Area> getAffectedAreas() {
		return affectedAreas;
	}
	
	public String getActingCharacterDescription() {
		return actingCharacterDescription;
	}
	
	public void setActingCharacterDescription(String newDesc) {
		actingCharacterDescription = newDesc;
	}
	
	public String getTargetCharacterDescription(GameCharacter character) {
		return targetDescriptions.get(character);
	}
	
	public void setTargetCharacterDescription(GameCharacter character, String newDesc) {
		targetDescriptions.put(character, newDesc);
	}
	
	public String getOnlookerDescription(GameCharacter character) {
		return onlookerDescriptions.get(character);
	}
	
	public void setOnlookerDescription(GameCharacter character, String newDesc) {
		onlookerDescriptions.put(character, newDesc);
	}
	
	public void setActingCharacter(GameCharacter character) {
		actingCharacter = character;
	}
	
	public void addTargetCharacter(GameCharacter character) {
		targetCharacters.add(character);
	}
	
	public void addOnlooker(GameCharacter character, String description) {
		onlookers.add(character);
		onlookerDescriptions.put(character, description);
	}
	
	public void addOnlookers(Set<GameCharacter> characters, String message) {
		onlookers.addAll(characters);
		for (GameCharacter character : characters) {
			if (onlookerDescriptions.containsKey(character)) {
				onlookerDescriptions.put(character, onlookerDescriptions.get(character) + "\n\n" + message);
			} else {
				onlookerDescriptions.put(character, message);
			}
		}
	}
	
	public void clearOnlookers() {
		onlookers = new HashSet<GameCharacter>();
		onlookerDescriptions = new HashMap<GameCharacter, String>();
	}
	
	public void removeTargetCharacter(GameCharacter character) {
		targetCharacters.remove(character);
	}
	
	public void remoteOnlooker(GameCharacter character) {
		onlookers.remove(character);
	}
	
	public GameCharacter getActingCharacter() {
		return actingCharacter;
	}
	
	public Set<GameCharacter> getTargetCharacters() {
		return targetCharacters;
	}
	
	public Set<GameCharacter> getOnlookers() {
		return onlookers;
	}
	
	public boolean isActionCompleted() {
		return actionCompleted;
	}
	
	public void setActionComplete() {
		actionCompleted = true;
	}
	
	public boolean isActionError() {
		return actionError;
	}
	
	public void setActionError() {
		actionError = true;
	}
	
	public boolean isOnlooker(GameCharacter gc) {
		for (GameCharacter g : onlookers) {
			if (g.equals(gc)) {
				return true;
			}
		}
		return false;
	}
	
	public String getSystemMessage() {
		return systemMessage;
	}
	
	public void setSystemMessage(String sm) {
		systemMessage = sm;
	}
}
